/* 
  节流：在规定时间内，同一事件多次触发只会执行一次
*/

const throttle = function (fn, delay) {
  let isIdle = true
  return function () {
    if (!isIdle) return
    isIdle = false
    let timer = setTimeout(() => {
      fn()
      clearTimeout(timer)
      timer = null
      isIdle = true
    }, delay)
  }
}